//package com.zhang.authoritycenter.common.config;
//
//import com.zhang.authoritycenter.common.properties.BaseProperties;
//import lombok.RequiredArgsConstructor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.util.CollectionUtils;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
//import org.springframework.web.filter.CorsFilter;
//
///**
// * 跨域问题
// */
//@RequiredArgsConstructor
//@Configuration
//public class CorsConfig {
//
//    private final BaseProperties baseProperties;
//
//    @Bean
//    public CorsFilter corsFilter() {
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        source.registerCorsConfiguration("/**", buildConfig());
//        return new CorsFilter(source);
//    }
//
////    @Bean
////    public CorsWebFilter corsWebFilter() {
////        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
////        source.registerCorsConfiguration("/**", buildConfig());
////        return new CorsWebFilter(source);
////    }
//
//    private CorsConfiguration buildConfig() {
//        CorsConfiguration corsConfiguration = new CorsConfiguration();
//        if (CollectionUtils.isEmpty(baseProperties.getOriginList())) {
//            corsConfiguration.addAllowedOrigin("*");
//        } else {
//            baseProperties.getOriginList().forEach(corsConfiguration::addAllowedOrigin);
//        }
//        corsConfiguration.addAllowedHeader("*");
//        corsConfiguration.addAllowedMethod("*");
//        return corsConfiguration;
//    }
//
//}
